import React from 'react';
import ReactDOM from 'react-dom';
import {Route, BrowserRouter,Switch} from 'react-router-dom';
import Button from 'antd/lib/button';
import PCIndex from './components/pc_index';
import PCNewsDetails from './components/pc_news_details';
import PCUserCenter from './components/pc_usercenter';
import MIndex from './components/m_index';
import MNewsDetails from './components/m_news_details';
import MUserCenter from './components/m_usercenter';
import 'antd/dist/antd.css';
import MediaQuery from 'react-responsive';
import {createStore} from 'redux';
import reducer from './components/reducers';


export default class Root extends React.Component {
	inc(){
		return {type:'ADD'};
	};
	dec(){
		return {type:'SUB'};
	};

	componentDidMount() {
		//初始化，传递发参数是reducer
		var store=createStore(reducer);
		console.log(store.getState());
		store.dispatch(this.inc());
		console.log(store.getState());
		store.dispatch(this.inc());
		console.log(store.getState());
		store.dispatch(this.dec());
		console.log(store.getState());
		
	};
	render() {
		return (
			//这里替换了之前的 Index，变成了程序的入口 //exact是router4强制只匹配/根目录
			<div>

				<MediaQuery query='(min-device-width:1224px)'>
					<BrowserRouter>
			   		<Switch>
						<Route exact path="/" component={PCIndex}></Route>	
						<Route path="/details/:uniquekey" component={PCNewsDetails}></Route>
						<Route path="/usercenter" component={PCUserCenter}></Route>
					</Switch>
					</BrowserRouter>		   
				</MediaQuery>
				<MediaQuery query='(max-device-width:1224px)'>
					<BrowserRouter>
			   		<Switch>
						<Route exact path="/" component={MIndex}></Route>
						<Route path="/details/:uniquekey" component={MNewsDetails}></Route>
						<Route path="/usercenter" component={MUserCenter}></Route>
					</Switch>
					</BrowserRouter>
				</MediaQuery>			
	        </div>
		);
	};
}

ReactDOM.render(
	<Root/>, document.getElementById('mainContainer')
);
